package com.example.orderflow.controller.flow;

import com.example.orderflow.controller.base.ABaseController;
import com.example.orderflow.entity.vo.ResponseVO;
import com.example.orderflow.service.ApprovalStageService;
import com.example.orderflow.service.ApproveHistoryService;
import com.example.orderflow.service.OrderInfoService;
import com.example.orderflow.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


/**
 * 审核阶段：订单入库
 * 审核等级：8
 */
@RestController
public class OrderStorageController extends ABaseController {

    @Autowired
    UserInfoService userInfoService;

    @Autowired
    ApprovalStageService approvalStageService;

    @Autowired
    ApproveHistoryService approveHistoryService;

    @Autowired
    OrderInfoService orderInfoService;

    /**
     * 订单入库 通过 8
     * @param map
     * orderId 订单编号
     * approveBy 审批人
     * @return
     */
    @PostMapping("/orderStoragePass")
    protected <T> ResponseVO orderStoragePass(@RequestBody Map<String,String> map) {

        String orderId = map.get("orderId"); //订单号
        String approveBy = map.get("userName"); //审批人

        String levelIdS = "8";

        //更改单人审核状态
        approveHistoryService.updateDefaultApproveHistory(orderId,levelIdS,approveBy,"已通过");

        //更改订单审核状态
        orderInfoService.updateOrderInfoLevelName(orderId,"已完结");

        return getSuccessResponseVO("该订单已入库已完成");

    }

}
